<template>
    <div style="padding: 30px;">
        <el-alert
        title="购票界面"
        type="info"
        :closable="false"
        show-icon
        description="请先选择乘车人及座位，之后进行后付款"
        effect="dark"/>
    
        <div style="padding:10px">
        <el-steps :active="active" finish-status="success" simple>
        <el-step title="选择乘车人及其座位"></el-step>
        <el-step title="去支付"></el-step>
        </el-steps>
        </div>
        <div v-if="active===0">
            <el-card class="box-card" style="text-align: center;">
                <el-button type="primary" @click="addPaseenger" icon="el-icon-plus" style="margin-bottom: 20px;">添加乘车人</el-button>
                <div v-for="p in PassengerList" :key="p.card">
                <el-descriptions :column="4" v-show="PassengerList" border :contentStyle="{'width':'120px'}" :label-style="{'width':'100px'}">
                    <el-descriptions-item>
                    <template slot="label">
                        <i class="el-icon-user"></i>
                        姓名
                    </template>
                    {{p.name}}
                    </el-descriptions-item>
                    <el-descriptions-item>
                    <template slot="label">
                        <svg-icon icon-class="people"/>
                        类别
                    </template>
                    {{p.kind}}
                    </el-descriptions-item>
                    <el-descriptions-item>
                    <template slot="label">
                        <i class="el-icon-bank-card"></i>
                        身份证号
                    </template>
                    {{p.card}}
                    </el-descriptions-item>
                    <el-descriptions-item>
                    <template slot="label">
                        <i class="el-icon-setting"></i>
                        操作
                    </template>
                    <el-button   circle @click="selectSeat(p)"><svg-icon icon-class="Microsoft-Fluentui-Emoji-Flat-Seat-Flat"></svg-icon></el-button>
                    <el-button  type="danger" icon="el-icon-delete" circle @click="deletePassenger(p)"></el-button>
                    
                    </el-descriptions-item>
                </el-descriptions>
                </div>
                <el-button style="margin-top: 20px;" v-show="step2" type="primary" @click="secondStep"><svg-icon icon-class="arrow-right-circle"></svg-icon>下一步</el-button>
            </el-card>
        </div>
        <div v-if="active===1">
            <el-card class="box-card" style="text-align: center;">
                <div v-for="o in orderList" :key="o.order_id">
                <el-descriptions :column="4" v-show="PassengerList" border :contentStyle="{'width':'120px'}" :label-style="{'width':'100px'}">
                    <el-descriptions-item>
                    <template slot="label">
                        <i class="el-icon-user"></i>
                        乘车人
                    </template>
                    {{o.passenger_name}}
                    </el-descriptions-item>
                    <el-descriptions-item>
                    <template slot="label">
                        <i class="el-icon-bank-card"></i>
                        身份证号
                    </template>
                    {{o.passenger_card}}
                    </el-descriptions-item>
                    <el-descriptions-item>
                    <template slot="label">
                        <i class="el-icon-bank-card"></i>
                        座位信息
                    </template>
                    {{o.carriage_no}}车厢--{{seatDetail(o.carriage_no,o.seat_no)}}
                    </el-descriptions-item>
                    <el-descriptions-item>
                    <template slot="label">
                        <i class="el-icon-setting"></i>
                        操作
                    </template>
                    <el-button  type="danger" icon="el-icon-shopping-cart-full" circle @click="payOrder(o)"></el-button>
                    </el-descriptions-item>
                </el-descriptions>
                </div>
                <el-button style="margin-top: 20px;"  type="primary" @click="exit2()" icon="el-icon-house">离开</el-button>
            </el-card>
        </div>
        <el-dialog title="选择乘车人" :visible.sync="dialogFormVisible">
        <el-checkbox-group v-model="PassengerList">
            <el-checkbox v-for="p in allPassenger" :label="p" :key="p.card" style="display:block; margin-top: 10px; margin-left: 10px; width:100px" border size="medium">
                {{ p.name }}
            </el-checkbox>
        </el-checkbox-group>
        </el-dialog>
        <el-dialog :title="'为乘客‘'+passengerName+'’选择座位'" :visible.sync="dialogSeatVisible" width="50%">
            <div class="el-dialog-div">
                <el-table :data="seat_info1"  style="width: 100%" border>
                    <el-table-column width="70" prop="carriage_no" label="车厢号"></el-table-column>
                    <el-table-column width="70" prop="seat_type" label="类型"></el-table-column>
                    <el-table-column width="50" prop="A" label="A"></el-table-column>
                    <el-table-column width="50" prop="B" label="B"></el-table-column>
                    <el-table-column width="50" prop="C" label="C"></el-table-column>
                    <el-table-column width="50" prop="D" label="D"></el-table-column>
                    <el-table-column width="50" prop="E" label="E"></el-table-column>
                    
                        <el-table-column label="选择">
                            <template slot-scope="scope">
                                <el-button-group>
                                <el-button  type="primary" size="small" @click="selectA1(scope.row)" :disabled="scope.row.A===0">A</el-button>
                                <el-button type="primary" size="small" @click="selectB1(scope.row)" :disabled="scope.row.B===0">B</el-button>
                                <el-button :disabled="scope.row.C===0" @click="selectC1(scope.row)" type="primary" size="small" v-if="scope.row.carriage_no === '3' || scope.row.carriage_no === '4' || scope.row.carriage_no === '5'|| scope.row.carriage_no === '6'|| scope.row.carriage_no === '7' || scope.row.carriage_no === '8'">C</el-button>
                                <el-button :disabled="scope.row.D===0" @click="selectD1(scope.row)" type="primary" size="small" v-if="scope.row.carriage_no === '5'|| scope.row.carriage_no === '6'|| scope.row.carriage_no === '7'|| scope.row.carriage_no === '8'">D</el-button>
                                <el-button :disabled="scope.row.E===0" @click="selectE1(scope.row)" type="primary" size="small" v-if="scope.row.carriage_no === '5'|| scope.row.carriage_no === '6'|| scope.row.carriage_no === '7'|| scope.row.carriage_no === '8'">E</el-button>
                        </el-button-group>
                            </template>
                    </el-table-column>
                </el-table>
                <el-divider>这是一条分割线</el-divider>
                <el-table :data="seat_info2"  style="width: 100%" border>
                    <el-table-column width="70" prop="carriage_no" label="车厢号"></el-table-column>
                    <el-table-column width="70" prop="seat_type" label="类型"></el-table-column>
                    <el-table-column width="50" prop="A" label="A"></el-table-column>
                    <el-table-column width="50" prop="B" label="B"></el-table-column>
                    <el-table-column width="50" prop="C" label="C"></el-table-column>
                    <el-table-column width="50" prop="D" label="D"></el-table-column>
                    <el-table-column width="50" prop="E" label="E"></el-table-column>
                    
                        <el-table-column label="选择">
                            <template slot-scope="scope">
                                <el-button-group>
                                <el-button  type="primary" size="small" @click="selectA2(scope.row)" :disabled="scope.row.A===0">A</el-button>
                                <el-button type="primary" size="small" @click="selectB2(scope.row)" :disabled="scope.row.B===0">B</el-button>
                                <el-button :disabled="scope.row.C===0" @click="selectC2(scope.row)" type="primary" size="small" v-if="scope.row.carriage_no === '3' || scope.row.carriage_no === '4' || scope.row.carriage_no === '5'|| scope.row.carriage_no === '6'|| scope.row.carriage_no === '7' || scope.row.carriage_no === '8'">C</el-button>
                                <el-button :disabled="scope.row.D===0" @click="selectD2(scope.row)" type="primary" size="small" v-if="scope.row.carriage_no === '5'|| scope.row.carriage_no === '6'|| scope.row.carriage_no === '7'|| scope.row.carriage_no === '8'">D</el-button>
                                <el-button :disabled="scope.row.E===0" @click="selectE2(scope.row)" type="primary" size="small" v-if="scope.row.carriage_no === '5'|| scope.row.carriage_no === '6'|| scope.row.carriage_no === '7'|| scope.row.carriage_no === '8'">E</el-button>
                        </el-button-group>
                            </template>
                    </el-table-column>
                </el-table>
            </div>
        </el-dialog>
        <div v-if="deadline!=null">
        <el-row :gutter="10">
      <el-col :span="8">
        <el-card shadow="hover" style="width: 40%;">
          <div style="width: 100%; display: inline-block; ">
            <el-statistic :value="deadline" time-indices title="付款倒计时">
            </el-statistic>
          </div>
        </el-card>
        </el-col>
        </el-row>
        </div>
        <div v-if="active===2">
            <el-result icon="success" title="成功提示" subTitle="恭喜你付款成功！！">
            <template slot="extra">
                <el-button type="primary" size="medium" @click="back">返回</el-button>
            </template>
            </el-result>
        </div>
        <div v-if="active===3">
            <el-result icon="info" title="消息提示" subTitle="未支付的订单可以在个人订单中完成支付！！">
            <template slot="extra">
                <el-button type="primary" size="medium" @click="back">返回</el-button>
            </template>
            </el-result>
        </div>
    </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { getList} from '@/api/table'
import {querySeat} from '@/api/train'
import {purchaseTicket,payTicket,queryStatus} from '@/api/order'
import moment from 'moment'

export default{
name:"Transfer",
data(){
    return{
        active: 0,
        dialogFormVisible:false,
        dialogSeatVisible:false,
        passengerName:'admin',
        passengerCard:'111',
        step2:false,
        allPassenger:null,
        PassengerList:[],
        train_info:null,//这里是一个
        seat_info1:null,
        seat_info2:null,
        occupation1:null,
        occupation2:null,
        baseCost1:null,
        realCost1:null,
        baseCost2:null,
        realCost2:null,
        seat_no1:null,
        seat_no2:null,
        create_time:null,
        orderList:[],
        deadline:null,
        clickNumber:0,
    }
},
created(){
        this.train_info=this.$route.params.train_info//由其他地方跳转过来的路由传参在这里接收
        getList({username: this.name}).then(response => {
        this.allPassenger = response.data.data
        })
        //对第一趟车初始化
        querySeat({train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,end_station_no:this.train_info.middle_station_no})
        .then(response =>{
            this.seat_info1=response.data.data
            this.occupation1=response.data.cook
            this.seat_info1.forEach(ite =>{
                if(ite.carriage_no === '1' || ite.carriage_no === '2'){
                    this.$set(ite,"A",10)
                    this.$set(ite,"B",10)
                    this.$set(ite,"C",'----')
                    this.$set(ite,"D",'----')
                    this.$set(ite,"E","----")
                }
                if(ite.carriage_no === '3' || ite.carriage_no ==='4'){
                    this.$set(ite,"A",10)
                    this.$set(ite,"B",10)
                    this.$set(ite,"C",10)
                    this.$set(ite,"D",'----')
                    this.$set(ite,"E","----")
                }
                if(ite.carriage_no === '5' || ite.carriage_no === '6' || ite.carriage_no === '7' || ite.carriage_no === '8'){
                    this.$set(ite,"A",10)
                    this.$set(ite,"B",10)
                    this.$set(ite,"C",10)
                    this.$set(ite,"D",10)
                    this.$set(ite,"E",10)
                }
            })
            this.seat_info1.forEach(element =>{
                var occuA=0
                var occuB=0
                var occuC=0
                var occuD=0
                var occuE=0
                this.occupation1.forEach(item =>{
                    if(element.carriage_no === item.carriage_no){
                        if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                            if(item.seat_no%2===0){occuB++}
                            else{occuA++}
                        }
                        if(element.carriage_no === '3'||element.carriage_no === '4'){
                            if(item.seat_no%3===0){occuC++}
                            else if(item.seat_no%3===2){occuB++}
                            else{occuA++}
                        }
                        if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                            if(item.seat_no%5===0){occuE++}
                            else if(item.seat_no%5===4){occuD++}
                            else if(item.seat_no%5===3){occuC++}
                            else if(item.seat_no%5===2){occuB++}
                            else{occuA++}
                        }
                    }
                })
                        if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                            element.A=element.A-occuA
                            element.B=element.B-occuB
                        }
                        if(element.carriage_no === '3'||element.carriage_no === '4'){
                            element.A=element.A-occuA
                            element.B=element.B-occuB
                            element.C=element.C-occuC
                        
                        }
                        if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                            element.A=element.A-occuA
                            element.B=element.B-occuB
                            element.C=element.C-occuC
                            element.D=element.D-occuD
                            element.E=element.E-occuE
                        }
            })
            if(moment('2018-10-20 '+this.train_info.t1_start_time).isBefore('2018-10-20 '+this.train_info.t1_end_time)){
        this.baseCost1 = moment('2021-08-17 '+this.train_info.t1_end_time).diff(moment('2021-08-17 '+this.train_info.t1_start_time),'minutes')*0.833
        }
        else{
        this.baseCost1 = moment('2021-08-18 '+this.train_info.t1_end_time).diff(moment('2021-08-17 '+this.train_info.t1_start_time),'minutes')*0.833
        }
        })
        //对第二趟车初始化
        querySeat({train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,end_station_no:this.train_info.end_station_no})
        .then(response =>{
            this.seat_info2=response.data.data
            this.occupation2=response.data.cook
            this.seat_info2.forEach(ite =>{
                if(ite.carriage_no === '1' || ite.carriage_no === '2'){
                    this.$set(ite,"A",10)
                    this.$set(ite,"B",10)
                    this.$set(ite,"C",'----')
                    this.$set(ite,"D",'----')
                    this.$set(ite,"E","----")
                }
                if(ite.carriage_no === '3' || ite.carriage_no ==='4'){
                    this.$set(ite,"A",10)
                    this.$set(ite,"B",10)
                    this.$set(ite,"C",10)
                    this.$set(ite,"D",'----')
                    this.$set(ite,"E","----")
                }
                if(ite.carriage_no === '5' || ite.carriage_no === '6' || ite.carriage_no === '7' || ite.carriage_no === '8'){
                    this.$set(ite,"A",10)
                    this.$set(ite,"B",10)
                    this.$set(ite,"C",10)
                    this.$set(ite,"D",10)
                    this.$set(ite,"E",10)
                }
            })
            this.seat_info2.forEach(element =>{
                var occuA=0
                var occuB=0
                var occuC=0
                var occuD=0
                var occuE=0
                this.occupation2.forEach(item =>{
                    if(element.carriage_no === item.carriage_no){
                        if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                            if(item.seat_no%2===0){occuB++}
                            else{occuA++}
                        }
                        if(element.carriage_no === '3'||element.carriage_no === '4'){
                            if(item.seat_no%3===0){occuC++}
                            else if(item.seat_no%3===2){occuB++}
                            else{occuA++}
                        }
                        if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                            if(item.seat_no%5===0){occuE++}
                            else if(item.seat_no%5===4){occuD++}
                            else if(item.seat_no%5===3){occuC++}
                            else if(item.seat_no%5===2){occuB++}
                            else{occuA++}
                        }
                    }
                })
                        if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                            element.A=element.A-occuA
                            element.B=element.B-occuB
                        }
                        if(element.carriage_no === '3'||element.carriage_no === '4'){
                            element.A=element.A-occuA
                            element.B=element.B-occuB
                            element.C=element.C-occuC
                        
                        }
                        if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                            element.A=element.A-occuA
                            element.B=element.B-occuB
                            element.C=element.C-occuC
                            element.D=element.D-occuD
                            element.E=element.E-occuE
                        }
            })
            if(moment('2018-10-20 '+this.train_info.t2_start_time).isBefore('2018-10-20 '+this.train_info.t2_end_time)){
        this.baseCost2 = moment('2021-08-17 '+this.train_info.t2_end_time).diff(moment('2021-08-17 '+this.train_info.t2_start_time),'minutes')*0.833
        }
        else{
        this.baseCost2 = moment('2021-08-18 '+this.train_info.t2_end_time).diff(moment('2021-08-17 '+this.train_info.t2_start_time),'minutes')*0.833
        }
        })
    },
computed: {
    ...mapGetters([
      'name'
    ])
  },
watch:{
    'PassengerList'(val){
        if(val.length === 0){
            this.step2=false
        }
        else{
            this.step2=true
        }
    },
    'clickNumber'(val){
        if(val === this.orderList.length){
            this.active=2
            this.deadline=null
        }
    }
},
methods:{
    back(){
        this.$router.push({name:'Order'})
    },
    selectA1(row){
        console.log(row)
        if(row.carriage_no === '1' || row.carriage_no === '2'){
            this.realCost1=parseFloat(this.realCost1*3).toFixed(0)
            querySeat({train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,end_station_no:this.train_info.middle_station_no})
            .then(response =>{
            this.occupation1=response.data.cook
            var empty_A=['1','3','5','7','9','11','13','15','17','19']
            this.occupation1.forEach(element =>{
                if(element.carriage_no === row.carriage_no && element.seat_no%2 ===1){
                    empty_A.forEach((item,index)=>{
                    if(item === element.seat_no){
                        empty_A.splice(index,1)
                    }
                    })
                }
            })
            this.seat_no1=empty_A[0]
            this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
            }
        else if(row.carriage_no === '3' || row.carriage_no === '4'){
            this.realCost1=parseFloat(this.realCost1*1.5).toFixed(0)
            querySeat({train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,end_station_no:this.train_info.middle_station_no})
            .then(response =>{
                this.occupation1=response.data.cook
                var empty_A=['1','4','7','10','13','16','19','22','25','28']
                this.occupation1.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%3===1){
                        empty_A.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_A.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no1=empty_A[0]
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        else{
            this.realCost1=parseFloat(this.realCost1*1.0).toFixed(0)
            querySeat({train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,end_station_no:this.train_info.middle_station_no})
            .then(response =>{
                this.occupation1=response.data.cook
                var empty_A=['1','6','11','16','21','26','31','36','41','46']
                this.occupation1.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%5===1){
                        empty_A.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_A.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no1=empty_A[0]
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        this.$confirm('为乘车人'+this.passengerName+'选购该座位,确认后不能更改', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            const loading = this.$loading({
            lock: true,
            text: '正拼命加载中......',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
            })
            console.log(this.train_info.t1_no,"*****")
            purchaseTicket({username:this.name,passenger_card:this.passengerCard,train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,start_station_name:this.train_info.t1_start_station,end_station_no:this.train_info.middle_station_no,end_station_name:this.train_info.t1_end_station,carriage_no:row.carriage_no,seat_no:this.seat_no1,price:'￥'+this.realCost1,create_time:this.create_time})
            .then(response =>{
            loading.close()
            this.orderList.push(response.data.data)
            this.deadline=Date.now() + 1000 * 60 * 15
            if(response.code===200){
                querySeat({train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,end_station_no:this.train_info.middle_station_no})
                .then(response =>{
                this.occupation1=response.data.cook
                this.seat_info1.forEach(element =>{
                var occuA=0
                var occuB=0
                var occuC=0
                var occuD=0
                var occuE=0
                this.occupation1.forEach(item =>{
                if(element.carriage_no === item.carriage_no){
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        if(item.seat_no%2===0){occuB++}
                        else{occuA++}
                }
                if(element.carriage_no === '3'||element.carriage_no === '4'){
                    if(item.seat_no%3===0){occuC++}
                    else if(item.seat_no%3===2){occuB++}
                    else{occuA++}
                }
                if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                    if(item.seat_no%5===0){occuE++}
                    else if(item.seat_no%5===4){occuD++}
                    else if(item.seat_no%5===3){occuC++}
                    else if(item.seat_no%5===2){occuB++}
                    else{occuA++}
                }
            }
        })
                if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                    element.A=10
                    element.B=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                }
                if(element.carriage_no === '3'||element.carriage_no === '4'){
                    element.A=10
                    element.B=10
                    element.C=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                    element.C=element.C-occuC
                    
                }
                if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                    element.A=10
                    element.B=10
                    element.C=10
                    element.D=10
                    element.E=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                    element.C=element.C-occuC
                    element.D=element.D-occuD
                    element.E=element.E-occuE
                }
            })
            })
                this.$message({
                message:response.data.message,
                type:'success'
            })
            }
            }).catch((response) => {
                    loading.close()}
                )
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选座'
          });          
        });
    },
    selectB1(row){
        if(row.carriage_no === '1' || row.carriage_no === '2'){
            this.realCost1=parseFloat(this.realCost1*3).toFixed(0)
            querySeat({train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,end_station_no:this.train_info.middle_station_no})
            .then(response =>{
                this.occupation1=response.data.cook
                var empty_B=['2','4','6','8','10','12','14','16','18','20']
                this.occupation1.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%2===0){
                        empty_B.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_B.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no1=empty_B[0]
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        else if(row.carriage_no === '3' || row.carriage_no === '4'){
            this.realCost1=parseFloat(this.realCost1*1.5).toFixed(0)
            querySeat({train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,end_station_no:this.train_info.middle_station_no})
            .then(response =>{
                this.occupation1=response.data.cook
                var empty_B=['2','5','8','11','14','17','20','23','26','29']
                this.occupation1.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%3===2){
                        empty_B.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_B.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no1=empty_B[0]
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        else{
            this.realCost1=parseFloat(this.realCost1*1.0).toFixed(0)
            querySeat({train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,end_station_no:this.train_info.middle_station_no})
            .then(response =>{
                this.occupation1=response.data.cook
                var empty_B=['2','7','12','17','22','27','32','37','42','47']
                this.occupation1.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%5===2){
                        empty_B.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_B.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no1=empty_B[0]
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        this.$confirm('为乘车人'+this.passengerName+'选购该座位,确认后不能更改', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            const loading = this.$loading({
            lock: true,
            text: '抢购中......',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
            });
            purchaseTicket({username:this.name,passenger_card:this.passengerCard,train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,start_station_name:this.train_info.t1_start_station,end_station_no:this.train_info.middle_station_no,end_station_name:this.train_info.t1_end_station,carriage_no:row.carriage_no,seat_no:this.seat_no1,price:'￥'+this.realCost1,create_time:this.create_time})
            .then(response =>{
            this.orderList.push(response.data.data)
            console.log(this.orderList)
            this.deadline=Date.now() + 1000 * 60 * 15
            loading.close()
                if(response.code===200){
                    querySeat({train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,end_station_no:this.train_info.middle_station_no})
                    .then(response =>{
                    this.occupation1=response.data.cook
                    this.seat_info1.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
            this.occupation1.forEach(item =>{
                if(element.carriage_no === item.carriage_no){
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        if(item.seat_no%2===0){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                      
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
        })
                })
                    loading.close()
                    this.$message({
                    message:response.data.message,
                    type:'success'
                })
                }
                }).catch((response) =>{ loading.close()}
                )
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选座'
          });          
        });
    },
    selectC1(row){
        if(row.carriage_no === '3' || row.carriage_no === '4'){
            this.realCost1=parseFloat(this.realCost1*1.5).toFixed(0)
            querySeat({train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,end_station_no:this.train_info.middle_station_no})
            .then(response =>{
                this.occupation1=response.data.cook
                var empty_C=['3','6','9','12','15','18','21','24','27','30']
                this.occupation1.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%3===0){
                        empty_C.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_C.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no1=empty_C[0]
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        else{
            this.realCost1=parseFloat(this.realCost1*1.0).toFixed(0)
            querySeat({train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,end_station_no:this.train_info.middle_station_no})
            .then(response =>{
                this.occupation1=response.data.cook
                var empty_C=['3','8','13','18','23','28','33','38','43','48']
                this.occupation1.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%5===3){
                        empty_C.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_C.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no1=empty_C[0]
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        this.$confirm('为乘车人'+this.passengerName+'选购该座位,确认后不能更改', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            const loading = this.$loading({
            lock: true,
            text: '抢购中......',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
            });
            purchaseTicket({username:this.name,passenger_card:this.passengerCard,train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,start_station_name:this.train_info.t1_start_station,end_station_no:this.train_info.middle_station_no,end_station_name:this.train_info.t1_end_station,carriage_no:row.carriage_no,seat_no:this.seat_no1,price:'￥'+this.realCost1,create_time:this.create_time})
            .then(response =>{
            this.orderList.push(response.data.data)
            this.deadline=Date.now() + 1000 * 60 * 15
            loading.close()
                if(response.code===200){
                    querySeat({train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,end_station_no:this.train_info.middle_station_no})
                    .then(response =>{
                    this.occupation1=response.data.cook
                    this.seat_info1.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
            this.occupation1.forEach(item =>{
                if(element.carriage_no === item.carriage_no){
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        if(item.seat_no%2===0){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                      
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
        })
                })
                    loading.close()
                    this.$message({
                    message:response.data.message,
                    type:'success'
                })
                }
                }).catch((response) =>{
                    loading.close()
                })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选座'
          });          
        });
    },    
    selectD1(row){
        this.realCost1=parseFloat(this.realCost1*1.0).toFixed(0)
        querySeat({train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,end_station_no:this.train_info.middle_station_no})
        .then(response =>{
            this.occupation1=response.data.cook
            var empty_D=['4','9','14','19','24','29','34','39','44','49']
            this.occupation1.forEach(element =>{
                if(element.carriage_no === row.carriage_no && element.seat_no%5===4){
                    empty_D.forEach((item,index) =>{
                        if(item === element.seat_no){
                            empty_D.splice(index,1)
                        }
                    })
                }
            })
            this.seat_no1=empty_D[0]
            this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
        })
        this.$confirm('为乘车人'+this.passengerName+'选购该座位,确认后不能更改', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            const loading = this.$loading({
            lock: true,
            text: '抢购中......',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
            });
            purchaseTicket({username:this.name,passenger_card:this.passengerCard,train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,start_station_name:this.train_info.t1_start_station,end_station_no:this.train_info.middle_station_no,end_station_name:this.train_info.t1_end_station,carriage_no:row.carriage_no,seat_no:this.seat_no1,price:'￥'+this.realCost1,create_time:this.create_time})
            .then(response =>{
            this.orderList.push(response.data.data)
            this.deadline=Date.now() + 1000 * 60 * 15
            loading.close()
                if(response.code===200){
                    querySeat({train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,end_station_no:this.train_info.middle_station_no})
                    .then(response =>{
                    this.occupation1=response.data.cook
                    this.seat_info1.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
            this.occupation1.forEach(item =>{
                if(element.carriage_no === item.carriage_no){
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        if(item.seat_no%2===0){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                      
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
        })
                })
                    loading.close()
                    this.$message({
                    message:response.data.message,
                    type:'success'
                })
                }
                }).catch((response)=>{ loading.close()}
                   
                )
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选座'
          });          
        });
    },
    selectE1(row){
        this.realCost1=parseFloat(this.realCost1*1.0).toFixed(0)
        querySeat({train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,end_station_no:this.train_info.middle_station_no})
        .then(response =>{
            this.occupation1=response.data.cook
            var empty_E=['5','10','15','20','25','30','35','40','45','50']
            this.occupation1.forEach(element =>{
                if(element.carriage_no === row.carriage_no && element.seat_no%5===0){
                    empty_E.forEach((item,index) =>{
                        if(item === element.seat_no){
                            empty_E.splice(index,1)
                        }
                    })
                }
            })
            this.seat_no1=empty_E[0]
            this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
        })
        this.$confirm('为乘车人'+this.passengerName+'选购该座位,确认后不能更改', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            const loading = this.$loading({
            lock: true,
            text: '抢购中......',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
            });
            purchaseTicket({username:this.name,passenger_card:this.passengerCard,train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,start_station_name:this.train_info.t1_start_station,end_station_no:this.train_info.middle_station_no,end_station_name:this.train_info.t1_end_station,carriage_no:row.carriage_no,seat_no:this.seat_no1,price:'￥'+this.realCost1,create_time:this.create_time})
            .then(response =>{
            loading.close()
            this.orderList.push(response.data.data)
            this.deadline=Date.now() + 1000 * 60 * 15
                if(response.code===200){
                    querySeat({train_no:this.train_info.t1_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.start_station_no,end_station_no:this.train_info.middle_station_no})
                    .then(response =>{
                    this.occupation1=response.data.cook
                    this.seat_info1.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
            this.occupation1.forEach(item =>{
                if(element.carriage_no === item.carriage_no){
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        if(item.seat_no%2===0){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                      
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
        })
                })
                    loading.close()
                    this.$message({
                    message:response.data.message,
                    type:'success'
                })
                }
                }).catch((response)=>{
                    loading.close()
                })
            
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选座'
          });          
        });
    },
    selectA2(row){
        console.log(row)
        if(row.carriage_no === '1' || row.carriage_no === '2'){
            this.realCost2=parseFloat(this.realCost2*3).toFixed(0)
            querySeat({train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,end_station_no:this.train_info.end_station_no})
            .then(response =>{
            this.occupation2=response.data.cook
            var empty_A=['1','3','5','7','9','11','13','15','17','19']
            this.occupation2.forEach(element =>{
                if(element.carriage_no === row.carriage_no && element.seat_no%2 ===1){
                    empty_A.forEach((item,index)=>{
                    if(item === element.seat_no){
                        empty_A.splice(index,1)
                    }
                    })
                }
            })
            this.seat_no2=empty_A[0]
            this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
            }
        else if(row.carriage_no === '3' || row.carriage_no === '4'){
            this.realCost2=parseFloat(this.realCost2*1.5).toFixed(0)
            querySeat({train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,end_station_no:this.train_info.end_station_no})
            .then(response =>{
                this.occupation2=response.data.cook
                var empty_A=['1','4','7','10','13','16','19','22','25','28']
                this.occupation2.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%3===1){
                        empty_A.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_A.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no2=empty_A[0]
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        else{
            this.realCost2=parseFloat(this.realCost2*1.0).toFixed(0)
            querySeat({train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,end_station_no:this.train_info.end_station_no})
            .then(response =>{
                this.occupation2=response.data.cook
                var empty_A=['1','6','11','16','21','26','31','36','41','46']
                this.occupation2.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%5===1){
                        empty_A.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_A.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no2=empty_A[0]
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        this.$confirm('为乘车人'+this.passengerName+'选购该座位,确认后不能更改', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            const loading = this.$loading({
            lock: true,
            text: '正拼命加载中......',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
            });
            purchaseTicket({username:this.name,passenger_card:this.passengerCard,train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,start_station_name:this.train_info.t2_start_station,end_station_no:this.train_info.end_station_no,end_station_name:this.train_info.t2_end_station,carriage_no:row.carriage_no,seat_no:this.seat_no2,price:'￥'+this.realCost2,create_time:this.create_time})
            .then(response =>{
            loading.close()
            this.orderList.push(response.data.data)
            this.deadline=Date.now() + 1000 * 60 * 15
            if(response.code===200){
                querySeat({train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,end_station_no:this.train_info.end_station_no})
                .then(response =>{
                this.occupation2=response.data.cook
                this.seat_info2.forEach(element =>{
                var occuA=0
                var occuB=0
                var occuC=0
                var occuD=0
                var occuE=0
                this.occupation2.forEach(item =>{
                if(element.carriage_no === item.carriage_no){
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        if(item.seat_no%2===0){occuB++}
                        else{occuA++}
                }
                if(element.carriage_no === '3'||element.carriage_no === '4'){
                    if(item.seat_no%3===0){occuC++}
                    else if(item.seat_no%3===2){occuB++}
                    else{occuA++}
                }
                if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                    if(item.seat_no%5===0){occuE++}
                    else if(item.seat_no%5===4){occuD++}
                    else if(item.seat_no%5===3){occuC++}
                    else if(item.seat_no%5===2){occuB++}
                    else{occuA++}
                }
            }
        })
                if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                    element.A=10
                    element.B=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                }
                if(element.carriage_no === '3'||element.carriage_no === '4'){
                    element.A=10
                    element.B=10
                    element.C=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                    element.C=element.C-occuC
                    
                }
                if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                    element.A=10
                    element.B=10
                    element.C=10
                    element.D=10
                    element.E=10
                    element.A=element.A-occuA
                    element.B=element.B-occuB
                    element.C=element.C-occuC
                    element.D=element.D-occuD
                    element.E=element.E-occuE
                }
            })
            })
                this.$message({
                message:response.data.message,
                type:'success'
            })
            }
            }).catch((response) => {
                    loading.close()}
                )
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选座'
          });          
        });
    },
    selectB2(row){
        if(row.carriage_no === '1' || row.carriage_no === '2'){
            this.realCost2=parseFloat(this.realCost2*3).toFixed(0)
            querySeat({train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,end_station_no:this.train_info.end_station_no})
            .then(response =>{
                this.occupation2=response.data.cook
                var empty_B=['2','4','6','8','10','12','14','16','18','20']
                this.occupation2.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%2===0){
                        empty_B.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_B.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no2=empty_B[0]
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        else if(row.carriage_no === '3' || row.carriage_no === '4'){
            this.realCost2=parseFloat(this.realCost2*1.5).toFixed(0)
            querySeat({train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,end_station_no:this.train_info.end_station_no})
            .then(response =>{
                this.occupation2=response.data.cook
                var empty_B=['2','5','8','11','14','17','20','23','26','29']
                this.occupation2.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%3===2){
                        empty_B.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_B.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no2=empty_B[0]
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        else{
            this.realCost2=parseFloat(this.realCost2*1.0).toFixed(0)
            querySeat({train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,end_station_no:this.train_info.end_station_no})
            .then(response =>{
                this.occupation2=response.data.cook
                var empty_B=['2','7','12','17','22','27','32','37','42','47']
                this.occupation2.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%5===2){
                        empty_B.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_B.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no2=empty_B[0]
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        this.$confirm('为乘车人'+this.passengerName+'选购该座位,确认后不能更改', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            const loading = this.$loading({
            lock: true,
            text: '抢购中......',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
            });
            purchaseTicket({username:this.name,passenger_card:this.passengerCard,train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,start_station_name:this.train_info.t2_start_station,end_station_no:this.train_info.end_station_no,end_station_name:this.train_info.t2_end_station,carriage_no:row.carriage_no,seat_no:this.seat_no2,price:'￥'+this.realCost2,create_time:this.create_time})
            .then(response =>{
            this.orderList.push(response.data.data)
            console.log(this.orderList)
            this.deadline=Date.now() + 1000 * 60 * 15
            loading.close()
                if(response.code===200){
                    querySeat({train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,end_station_no:this.train_info.end_station_no})
                    .then(response =>{
                    this.occupation2=response.data.cook
                    this.seat_info2.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
            this.occupation2.forEach(item =>{
                if(element.carriage_no === item.carriage_no){
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        if(item.seat_no%2===0){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                      
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
        })
                })
                    loading.close()
                    this.$message({
                    message:response.data.message,
                    type:'success'
                })
                }
                }).catch((response) =>{ loading.close()}
                )
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选座'
          });          
        });
    },
    selectC2(row){
        if(row.carriage_no === '3' || row.carriage_no === '4'){
            this.realCost1=parseFloat(this.realCost1*1.5).toFixed(0)
            querySeat({train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,end_station_no:this.train_info.end_station_no})
            .then(response =>{
                this.occupation2=response.data.cook
                var empty_C=['3','6','9','12','15','18','21','24','27','30']
                this.occupation2.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%3===0){
                        empty_C.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_C.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no2=empty_C[0]
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        else{
            this.realCost2=parseFloat(this.realCost2*1.0).toFixed(0)
            querySeat({train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,end_station_no:this.train_info.end_station_no})
            .then(response =>{
                this.occupation2=response.data.cook
                var empty_C=['3','8','13','18','23','28','33','38','43','48']
                this.occupation2.forEach(element =>{
                    if(element.carriage_no === row.carriage_no && element.seat_no%5===3){
                        empty_C.forEach((item,index) =>{
                            if(item === element.seat_no){
                                empty_C.splice(index,1)
                            }
                        })
                    }
                })
                this.seat_no2=empty_C[0]
                this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }
        this.$confirm('为乘车人'+this.passengerName+'选购该座位,确认后不能更改', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            const loading = this.$loading({
            lock: true,
            text: '抢购中......',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
            });
            purchaseTicket({username:this.name,passenger_card:this.passengerCard,train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,start_station_name:this.train_info.t2_start_station,end_station_no:this.train_info.end_station_no,end_station_name:this.train_info.t2_end_station,carriage_no:row.carriage_no,seat_no:this.seat_no2,price:'￥'+this.realCost2,create_time:this.create_time})
            .then(response =>{
            this.orderList.push(response.data.data)
            this.deadline=Date.now() + 1000 * 60 * 15
            loading.close()
                if(response.code===200){
                    querySeat({train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,end_station_no:this.train_info.end_station_no})
                    .then(response =>{
                    this.occupation2=response.data.cook
                    this.seat_info2.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
            this.occupation2.forEach(item =>{
                if(element.carriage_no === item.carriage_no){
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        if(item.seat_no%2===0){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                      
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
        })
                })
                    loading.close()
                    this.$message({
                    message:response.data.message,
                    type:'success'
                })
                }
                }).catch((response) =>{
                    loading.close()
                })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选座'
          });          
        });
    },    
    selectD2(row){
        this.realCost2=parseFloat(this.realCost2*1.0).toFixed(0)
        querySeat({train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,end_station_no:this.train_info.end_station_no})
        .then(response =>{
            this.occupation2=response.data.cook
            var empty_D=['4','9','14','19','24','29','34','39','44','49']
            this.occupation2.forEach(element =>{
                if(element.carriage_no === row.carriage_no && element.seat_no%5===4){
                    empty_D.forEach((item,index) =>{
                        if(item === element.seat_no){
                            empty_D.splice(index,1)
                        }
                    })
                }
            })
            this.seat_no2=empty_D[0]
            this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
        })
        this.$confirm('为乘车人'+this.passengerName+'选购该座位,确认后不能更改', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            const loading = this.$loading({
            lock: true,
            text: '抢购中......',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
            });
            purchaseTicket({username:this.name,passenger_card:this.passengerCard,train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,start_station_name:this.train_info.t2_start_station,end_station_no:this.train_info.end_station_no,end_station_name:this.train_info.t2_end_station,carriage_no:row.carriage_no,seat_no:this.seat_no2,price:'￥'+this.realCost2,create_time:this.create_time})
            .then(response =>{
            this.orderList.push(response.data.data)
            this.deadline=Date.now() + 1000 * 60 * 15
            loading.close()
                if(response.code===200){
                    querySeat({train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,end_station_no:this.train_info.end_station_no})
                    .then(response =>{
                    this.occupation2=response.data.cook
                    this.seat_info2.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
            this.occupation2.forEach(item =>{
                if(element.carriage_no === item.carriage_no){
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        if(item.seat_no%2===0){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                      
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
        })
                })
                    loading.close()
                    this.$message({
                    message:response.data.message,
                    type:'success'
                })
                }
                }).catch((response)=>{ loading.close()}
                   
                )
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选座'
          });          
        });
    },
    selectE2(row){
        this.realCost2=parseFloat(this.realCost2*1.0).toFixed(0)
        querySeat({train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,end_station_no:this.train_info.end_station_no})
        .then(response =>{
            this.occupation2=response.data.cook
            var empty_E=['5','10','15','20','25','30','35','40','45','50']
            this.occupation2.forEach(element =>{
                if(element.carriage_no === row.carriage_no && element.seat_no%5===0){
                    empty_E.forEach((item,index) =>{
                        if(item === element.seat_no){
                            empty_E.splice(index,1)
                        }
                    })
                }
            })
            this.seat_no2=empty_E[0]
            this.create_time=moment().format('YYYY-MM-DD HH:mm:ss')
        })
        this.$confirm('为乘车人'+this.passengerName+'选购该座位,确认后不能更改', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            const loading = this.$loading({
            lock: true,
            text: '抢购中......',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
            });
            purchaseTicket({username:this.name,passenger_card:this.passengerCard,train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,start_station_name:this.train_info.t2_start_station,end_station_no:this.train_info.end_station_no,end_station_name:this.train_info.t2_end_station,carriage_no:row.carriage_no,seat_no:this.seat_no2,price:'￥'+this.realCost2,create_time:this.create_time})
            .then(response =>{
            loading.close()
            this.orderList.push(response.data.data)
            this.deadline=Date.now() + 1000 * 60 * 15
                if(response.code===200){
                    querySeat({train_no:this.train_info.t2_no,arrive_day:this.train_info.arrive_day,start_station_no:this.train_info.middle2_station_no,end_station_no:this.train_info.end_station_no})
                    .then(response =>{
                    this.occupation2=response.data.cook
                    this.seat_info2.forEach(element =>{
                    var occuA=0
                    var occuB=0
                    var occuC=0
                    var occuD=0
                    var occuE=0
            this.occupation2.forEach(item =>{
                if(element.carriage_no === item.carriage_no){
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        if(item.seat_no%2===0){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        if(item.seat_no%3===0){occuC++}
                        else if(item.seat_no%3===2){occuB++}
                        else{occuA++}
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        if(item.seat_no%5===0){occuE++}
                        else if(item.seat_no%5===4){occuD++}
                        else if(item.seat_no%5===3){occuC++}
                        else if(item.seat_no%5===2){occuB++}
                        else{occuA++}
                    }
                }
            })
                    if(element.carriage_no === '1' ||element.carriage_no === '2' ){
                        element.A=10
                        element.B=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                    }
                    if(element.carriage_no === '3'||element.carriage_no === '4'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                      
                    }
                    if(element.carriage_no === '5'||element.carriage_no === '6'||element.carriage_no === '7'||element.carriage_no === '8'){
                        element.A=10
                        element.B=10
                        element.C=10
                        element.D=10
                        element.E=10
                        element.A=element.A-occuA
                        element.B=element.B-occuB
                        element.C=element.C-occuC
                        element.D=element.D-occuD
                        element.E=element.E-occuE
                    }
        })
                })
                    loading.close()
                    this.$message({
                    message:response.data.message,
                    type:'success'
                })
                }
                }).catch((response)=>{
                    loading.close()
                })
            
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选座'
          });          
        });
    },
    addPaseenger(){
        this.dialogFormVisible=true
    },
    deletePassenger(p){
        this.PassengerList.forEach((element,index) => {
            if(element.name === p.name && element.card === p.card){
                this.PassengerList.splice(index,1)
            }
        });
    },
    selectSeat(p){
        this.passengerName=p.name
        this.passengerCard=p.card
        this.dialogSeatVisible=true
        if(p.kind==='儿童' || p.kind === '老人'){
            this.realCost1=this.baseCost1*0.5
            this.realCost2=this.baseCost2*0.5
        }
        else if(p.kind === '学生'){
            this.realCost1=this.baseCost1*0.75
            this.realCost2=this.baseCost2*0.75
        }
        else{
            this.realCost1=this.baseCost1
            this.realCost2=this.baseCost2
        }
    },
    secondStep(){
        if(this.PassengerList.length*2!=this.orderList.length){
            this.$message({
            message: '存在所选乘车人,未选择够两趟车的座位',
            type: 'warning'
            });
        }
        else{
            this.step2=false
            this.active=1
        }
    },
    payOrder(o){
       payTicket(o).then(response =>{
        console.log(response)
        var url =response.data.url
        window.open(url, "_blank");
       }).catch(error =>{
        console.log(error)
       })
    },
    seatDetail(c_no,s_no){
        if(c_no==='1'||c_no==='2'){
            if(s_no%2===0){
                return (s_no/2)+"排B座"
            }
            else{
                return (parseFloat(s_no/2).toFixed(0))+"排A座"
            }
        }
        if(c_no ==='3' || c_no==='4'){
            if(s_no%3===0){
                return (s_no/3)+"排C座"
            }
            else if(s_no%3===2){
                return (parseInt(s_no/3)+1)+"排B座"
            }
            else{
                return (parseInt(s_no/3)+1)+"排A座"
            }
        }
        if(c_no === '5' || c_no === '6' || c_no === '7' || c_no === '8'){
            if(s_no%5===0){
                return (s_no/5)+"排E座"
            }
            else if(s_no%5===4){
                return (parseInt(s_no/5)+1)+"排D座"
            }
            else if(s_no%5===3){
                return (parseInt(s_no/5)+1)+"排C座"
            }
            else if(s_no%5===2){
                return (parseInt(s_no/5)+1)+"排B座"
            }
            else if(s_no%5===1){
                return (parseInt(s_no/5)+1)+"排A座"
            }
        }
    },
    exit2(){
    var payCount=0
    this.orderList.forEach(element =>{
        queryStatus({order_id:element.order_id}).then(response =>{
            if(response.data.status==='已付款'){
                payCount++
            }
        })
    })
    setTimeout(()=>{
        if(payCount===this.orderList.length){
        this.deadline=null
        this.active=2
    }
    else{
        this.active=3
    }   
    },1500)
    
    },
}
}
</script>

<style>
.el-dialog-div {
  height: 60vh;
  overflow-x: hidden;
}
.box-card {
    width: 880px;
    margin-left: auto;
    margin-right: auto;
  }
</style>